package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.mapper.WarningInfoMapper;
import com.example.demo.entity.Message;
import com.example.demo.entity.WarningInfos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class SearchWarByIdController {
    @Autowired
    private  WarningInfoMapper wm;
    @RequestMapping("/searchwarbyid")
    public void getWarById(HttpServletRequest request, HttpServletResponse response) throws IOException {
        int id;
        try {
            id=Integer.valueOf(request.getParameter("id"));
        } catch (NumberFormatException e) {
            response.getWriter().write(JSONObject.toJSONString(Message.failure("format error")));
            return;
        }
        List<WarningInfos> list=new ArrayList<>();
        list=wm.selectbyid(id);
        if(list!=null) response.getWriter().write(JSONObject.toJSONString(Message.success(list)));
        else response.getWriter().write(JSONObject.toJSONString(Message.failure("Can not find ")));
    }
}
